package drawingBoard.tool;

import drawingBoard.ImageFrame;

import javax.swing.*;

//import drawing.ImageFrame;

import java.awt.*;
import java.awt.event.MouseEvent;

//文字工具
public class TextTool extends AbstractTool {
    private static Tool tool = null;

    private TextTool(ImageFrame frame) {
        super(frame, "img/textcursor.gif");
    }

    public static Tool getInstance(ImageFrame frame) {
        if (tool == null) {
            tool = new TextTool(frame);
        }
        return tool;
    }


    //点击鼠标
    public void mouseClicked(MouseEvent e){
        super.mouseClicked(e);
        // 获取图片的Graphics对象
        Graphics g = getFrame().getBufferedImage().getGraphics();
        g.setColor(AbstractTool.color);
        getFrame().getDrawSpace().repaint();
        String string = JOptionPane.showInputDialog("请输入:");
        if(string == null) return;
        g.drawString(string, e.getX(), e.getY());
        getFrame().getDrawSpace().repaint();
    }
}
